﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DO.Workflows;

namespace BLL.Workflows
{
    public class ManualStartWorker:WorkerBase
    {
        #region Overrides of WorkerBase

        private ManualStartInstruction _Instruction;
        /// <summary>
        /// allow instruction to be changed at runtime
        /// </summary>
        public override InstructionBase Instruction
        {
            get
            {
                return _Instruction;
            }
            set
            {
                _Instruction = (ManualStartInstruction) value;
            }
        }

        private ManualStartOutput _Output;
        /// <summary>
        /// output
        /// </summary>
        public override ResultBase Output
        {
            get
            {
                return _Output;
            }
        }

        /// <summary>
        /// allow worker to be created based on component type
        /// </summary>
        public override Type ComponentType
        {
            get
            {
                return typeof (ManualStart);
            }
        }

        /// <summary>
        /// allow instruction to be instantiated
        /// </summary>
        public override Type InstructionType
        {
            get
            {
                return typeof (ManualStartInstruction);
            }
        }

        public override event WorkerFinished WorkerFinishedEvent;
        public override event WorkerHasError WorkerErredEvent;
        public override event WorkerStatusChanged WorkerStatusChangedEvent;
        protected override void StartWork()
        {
            try
            {
                this._Output = new ManualStartOutput();
                if (this.WorkerFinishedEvent != null)
                    this.WorkerFinishedEvent(this.JobTicket, this.GetType(), this.Instruction, this.Output);
            }
            catch(Exception ex)
            {
                if (this.WorkerErredEvent != null)
                    this.WorkerErredEvent(this.JobTicket, this.GetType(), this.Instruction, ex.Message, true);
            }
        }
        #endregion
    }
}
